using System;
using System.Collections.Generic;
using System.Linq;
using csvviewer.contracts;

namespace csvviewer.logic
{
	public class Prepend_line_index
	{
		public void Process(PageOfLines page)
		{
			page.Lines = Prepend_while_enumerating(page.Lines, page.PageInfo.NumberOfFirstLine);
			this.Page(page);
		}
		
		public event Action<PageOfLines> Page;

		
		public IEnumerable<string> Prepend_while_enumerating(IEnumerable<string> lines, int numberOfFirstLine)
		{
			var offset = -1;
			foreach(var l in lines)
			{
				if (offset < 0)
					yield return "No.;" + l;
				else
					yield return string.Format("{0}.;{1}", numberOfFirstLine+offset, l);
				offset++;
			}
		}
	}
}

